package com.only4play.productcenter.domain.product;


import com.only4play.codegen.processor.api.*;
import com.only4play.codegen.processor.controller.GenController;
import com.only4play.codegen.processor.creator.GenCreator;
import com.only4play.codegen.processor.creator.IgnoreCreator;
import com.only4play.codegen.processor.mapper.GenMapper;
import com.only4play.codegen.processor.query.GenQuery;
import com.only4play.codegen.processor.repository.GenRepository;
import com.only4play.codegen.processor.service.GenService;
import com.only4play.codegen.processor.service.GenServiceImpl;
import com.only4play.codegen.processor.updater.GenUpdater;
import com.only4play.codegen.processor.updater.IgnoreUpdater;
import com.only4play.codegen.processor.vo.GenVo;
import com.only4play.common.annotation.FieldDesc;
import com.only4play.common.annotation.TypeConverter;
import com.only4play.common.constants.ValidStatus;
import com.only4play.jpa.converter.ValidStatusConverter;
import com.only4play.jpa.support.BaseJpaAggregate;
import com.only4play.productcenter.api.constants.ProductType;
import com.only4play.productcenter.api.constants.SerializeType;
import com.only4play.productcenter.infrastructure.convert.SerializeTypeConverter;
import com.only4play.productcenter.infrastructure.constants.Constants;
import com.only4play.productcenter.infrastructure.convert.ProductTypeConverter;
import lombok.Data;

import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;

@GenVo(pkgName = "com.only4play.productcenter.domain.product.vo")
@GenCreator(pkgName = "com.only4play.productcenter.domain.product.creator")
@GenUpdater(pkgName = "com.only4play.productcenter.domain.product.updater")
@GenRepository(pkgName = "com.only4play.productcenter.domain.product.repository")
@GenService(pkgName = "com.only4play.productcenter.domain.product.service")
@GenServiceImpl(pkgName = "com.only4play.productcenter.domain.product.service")
@GenQuery(pkgName = "com.only4play.productcenter.domain.product.query")
@GenMapper(pkgName = "com.only4play.productcenter.domain.product.mapper")
@GenController(pkgName = "com.only4play.productcenter.web.controller")
@GenCreateRequest(pkgName = "com.only4play.productcenter.api.product.request", sourcePath = Constants.GEN_API_SOURCE)
@GenUpdateRequest(pkgName = "com.only4play.productcenter.api.product.request", sourcePath = Constants.GEN_API_SOURCE)
@GenQueryRequest(pkgName = "com.only4play.productcenter.api.product.request", sourcePath = Constants.GEN_API_SOURCE)
@GenResponse(pkgName = "com.only4play.productcenter.api.product.response", sourcePath = Constants.GEN_API_SOURCE)
@GenFeign(pkgName = "com.only4play.productcenter.api.product.service", sourcePath = Constants.GEN_API_SOURCE, serverName = "product-srv")
@Entity
@Table(name = "product")
@Data
public class Product extends BaseJpaAggregate {

    @FieldDesc(name = "模板id")
    private Long templateId;
    
    @FieldDesc(name = "品牌id")
    private Long brandId;

    @FieldDesc(name = "编码")
    private String code;

    @FieldDesc(name = "名称")
    private String name;

    @FieldDesc(name = "分类id")
    private Long categoryId;

    @FieldDesc(name = "描述")
    private String description;

    @FieldDesc(name = "类型")
    @Convert(converter = ProductTypeConverter.class)
    @TypeConverter(toTypeFullName = "java.lang.Integer")
    private ProductType type;

    @FieldDesc(name = "是否需要序列化")
    @Convert(converter = SerializeTypeConverter.class)
    @TypeConverter(toTypeFullName = "java.lang.Integer")
    private SerializeType serializeType;


    private Long pid;

    @Convert(converter = ValidStatusConverter.class)
    @IgnoreUpdater
    @IgnoreCreator
    private ValidStatus validStatus;

    public void init() {
        setValidStatus(ValidStatus.VALID);
    }

    public void valid() {
        setValidStatus(ValidStatus.VALID);
    }

    public void invalid() {
        setValidStatus(ValidStatus.INVALID);
    }
}
